package com.jmuok.web.fff.domain;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooDbManaged(automaticallyDelete = true)
@RooJpaActiveRecord(table = "user", finders = { "findUsersByUserNameAndPasswordAndAccountEnabledNotAndAccountExpiredNot", "findUsersByUserNameOrEmailAndPasswordAndAccountEnabledAndAccountLockedNotAndAccountExpiredNotAndCredentialsExpiredNot", "findUsersByUserNameOrEmail" })
public class User {

    public static TypedQuery<com.jmuok.web.fff.domain.User> findUsersByUserNameOrEmail(String userNameOrEmail) {
        if (userNameOrEmail == null || userNameOrEmail.length() == 0) throw new IllegalArgumentException("The userName or email argument is required");
        EntityManager em = User.entityManager();
        TypedQuery<User> q = em.createQuery("SELECT o FROM User AS o WHERE o.userName = :userName OR o.email = :email", User.class);
        q.setParameter("userName", userNameOrEmail);
        q.setParameter("email", userNameOrEmail);
        return q;
    }
}
